import { defineStore } from 'pinia';

const publish = defineStore({
  id: 'publish',
  state: () => ({
    // 发布弹框显示状态
    showModal: false,
    // 弹框是否准备就绪
    isReady: false,
    // 弹框标题
    modalTitle: '发布内容',
    // 弹框内容
    modalContent: '',
    // 回调函数
    onSuccess: null,
    onCancel: null
  }),
  actions: {
    // 显示发布弹框
    showPublishModal(options = {}) {
      console.log('Pinia store: 显示发布弹框', options);
      this.showModal = true;
      this.modalTitle = options.title || '发布内容';
      this.modalContent = options.content || '';
      this.onSuccess = options.onSuccess || null;
      this.onCancel = options.onCancel || null;
      this.isReady = true;
    },
    
    // 隐藏发布弹框
    hidePublishModal() {
      console.log('Pinia store: 隐藏发布弹框');
      this.showModal = false;
      this.isReady = false;
    },
    
    // 发布成功回调
    onPublishSuccess(data) {
      console.log('Pinia store: 发布成功', data);
      if (this.onSuccess) {
        this.onSuccess(data);
      }
      this.hidePublishModal();
    },
    
    // 取消发布回调
    onPublishCancel() {
      console.log('Pinia store: 取消发布');
      if (this.onCancel) {
        this.onCancel();
      }
      this.hidePublishModal();
    },
    
    // 设置弹框准备状态
    setReady(ready) {
      this.isReady = ready;
    }
  }
});

export default publish;